#ifndef _XTHREAD_H_
#define _XTHREAD_H_

#ifndef WIN32
#include <pthread.h>
#include <unistd.h>
#endif

#ifdef WIN32
#ifdef MAKEDLL
  #define XTHREAD_EXPORT __declspec(dllexport)
#else
  #define XTHREAD_EXPORT __declspec(dllimport)
#endif
#else
#define XTHREAD_EXPORT
#endif

class XTHREAD_EXPORT XThread
{
#ifdef WIN32
friend unsigned __stdcall XThread_runRelay( void* data );
#else
friend void* XThread_runRelay( void* data );
#endif

public:
  typedef enum{ PriorityNormal } Priority;

  XThread( Priority priority = PriorityNormal );
  virtual ~XThread();

  bool start();
  bool isRunning() const;
  virtual void run() = 0;
  virtual void kill();

  static void msleep( unsigned int msecs );

  void wait();

private:
#ifdef WIN32
  void* _hThread;
  unsigned int _dwThreadId;
#else
  pthread_t _hThread;
#endif
  Priority _priority;
  bool _isRunning;
};

#endif
